package m5;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.util.Scanner;

public class Producer {
    public static void main(String[] args) throws Exception{
        ConnectionFactory f = new ConnectionFactory();
        f.setPort(5672);
        f.setHost("192.168.64.140");
        f.setUsername("admin");
        f.setPassword("admin");
        //f.setVirtualHost(); 使用自己的空间使用
        Channel con = f.newConnection().createChannel();

        /*创建direct交换机 direct_logs*/
        con.exchangeDeclare("topic_log", BuiltinExchangeType.TOPIC);/*TOPIC交换机*/
        /*发送消息，在消息上携带路由键*/
        while (true){
            System.out.println("输入");
            String s = new Scanner(System.in).nextLine();
            System.out.println("输入路由键");
            String k = new Scanner(System.in).nextLine();
            /*第二个参数是路由键关键词*/
            /*吐过使用默认交换机，路由键就是队列名*/
            con.basicPublish("topic_log",k,null,s.getBytes());
        }
    }
}
